// 给定一个字符串 s ，你需要反转字符串中每个单词的字符顺序，同时仍保留空格和单词的初始顺序。

/**
 * @param {string} s
 * @return {string}
 */
 var reverseWords = function(s) {
    s = s.split(" ");
    let result = [];
    s.forEach(item => {
        result.push(reverseString(item))
    })
    return result.join(' ');
};

let reverseString = function(s){
    s = s.split('')
    let left = 0, right = s.length -1;
    while(left < right){
        let temp = s[right];
        s[right] = s[left];
        s[left] = temp;
        left = left + 1;
        right = right - 1;
    }
    return s.join("");
}

s = "Let's take LeetCode contest"
console.log(reverseWords(s));